﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI.WebControls;
using Entidades;
namespace WEB_IUS.Clases
{
    public class GenRoles
    {
        public string GenerarRoles()
        {
            using (iusEntities ctx = new iusEntities())
            {
                string strrole = "";
                List<menu> lm = (from c in ctx.menu
                                 select c).ToList<menu>();
                foreach (menu im in lm)
                {
                    string rol = im.ROL;
                    if (!String.IsNullOrEmpty(rol) && (!Roles.RoleExists(rol)))
                    {
                        Roles.CreateRole(rol);
                        Roles.AddUserToRole("1", rol);
                        strrole = strrole + rol + "<br>";
                    }
                    else if (!String.IsNullOrEmpty(rol) && (Roles.RoleExists(rol)) && (!Roles.IsUserInRole("1",rol)))
                    {
                        Roles.AddUserToRole("1", rol);
                        strrole = strrole + rol + "<br>";
                    }
                }
                return strrole;
            }
        }
    }
}